package array;

import org.junit.Test;

/**
 * @author way
 * @create 2024-12-03 10:40 https://leetcode.cn/problems/remove-element/description/
 */
public class _27_removeElement {
    public int removeElement(int[] nums, int val) {
        int j = nums.length;
        int k;
        for (int i = 0; i < j; i++) {
            if (nums[i] == val) {
                for (k = i + 1; k < j; k++) {
                    nums[k - 1] = nums[k];
                }
                j--;
                i--;
            }
        }

        return j;
    }

    @Test
    public void test() {
        int[] nums = { 1};
        System.out.println(nums[1]);
        int val = 1;
        System.out.println(removeElement(nums, val));
        for (int num : nums) {
            System.out.println(num);
        }
    }
}
